<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/js/jquery-3.6.0.min.js"></script>
    <link href="../css/company.css" type="text/css" rel="stylesheet">
</head>
<body>
<div th:include="common/inc"></div>
<form class="elegant-aero">
    <input type="hidden" th:value="${company.companyId}" name="companyId">      <!--保存主键，用于修改操作-->
    <h1>公司信息编辑
        <!--        <span>请填写全部信息</span>-->
    </h1>
    <label>
        <span>公司名称 :</span>
        <input id="companyName" type="text" th:value="${company.companyName}" name="companyName" placeholder="公司名称" />
    </label>
    <label>
        <span>公司介绍 :</span>
        <textarea id="companyShow" th:utext="${company.companyShow}" name="companyShow" placeholder="公司介绍"></textarea>
        <!--        <input id="companyShow" type="text" name="companyShow" placeholder="公司介绍" />-->
    </label>
    <label>
        <span>公司地址 :</span>
        <input id="companyAddress" th:value="${company.companyAddress}" type="text" name="companyAddress" placeholder="公司地址" />
    </label>

    <label>
        <span>行业类型 :</span>
        <select name="companyType">
            <option value="-1">请选择</option>
            <option th:each="c:${companyType}" th:selected="${c.dataName==company.companyType}" th:value="${c.dataName}" th:text="${c.dataName}"></option>
        </select>
    </label>
    <label>
        <span>公司规模 :</span>
        <select name="companySize">
            <option value="-1">请选择</option>
            <option th:each="s:${companySize}" th:selected="${s.dataName==company.companySize}" th:value="${s.dataName}" th:text="${s.dataName}"></option>
        </select>
    </label>
    <label>
        <span>融资阶段 :</span>
        <select name="financingPhase">
            <option value="-1">请选择</option>
            <option th:each="f:${financingPhase}" th:selected="${f.dataName==company.financingPhase}" th:value="${f.dataName}" th:text="${f.dataName}"></option>
        </select>
    </label>
    <label>
        <span>&nbsp;</span>
        <input type="button" class="button" id="add" value="发布" onclick="addCompany()">
        <input type="button" class="button" id="update" value="修改" onclick="updateCompany()">
    </label>
</form>
</body>
<script>

    $(function(){
        getCompany();
    })

    //查询
    function getCompany(){
        $.ajax({
            url:"/company/getCompany",
            type:"post",
            dataType:"json",    <!--设置返回值为json，就可以直接用 . 获取元素值-->
            success:function (data){
                <!--显示修改按钮-->
                $("#add").hide();
                $("#update").show();

            },error:function (){
                <!--若是没查到数据，即返回值为空，就会走error方法-->
                $("#update").hide();
                $("#add").show();
            }
        })
    }

    //新增
    function addCompany(){
        $.ajax({
            url:"/company/addCompany",
            type:"post",
            data:$("form").serialize(),
            success:function (){
                alert("新增成功");
                location.href="/company/toCompany";//跳转
            },error:function () {
                alert("新增失败");
            }
        })
    }

    //修改
    function updateCompany(){
        $.ajax({
            url:"/company/updateCompany",
            type:"post",
            data:$("form").serialize(),
            success:function (){
                alert("修改成功");
                location.href="/company/toCompany1";//跳转
            },error:function () {
                alert("修改失败");
            }
        })
    }


</script>

</html>